<template>
  <div class="login-container">
    <!-- 标题 -->
    <div class="title"></div>

    <!-- 输入表单 -->
    <div class="form">
      <div class="input-group">
        <label>账号</label>
        <input type="text" placeholder="请输入账号" v-model="form.username" />
      </div>

      <div class="input-group">
        <label>密码</label>
        <input type="password" placeholder="请输入密码" v-model="form.password" />
      </div>
    </div>

    <!-- 登录按钮 -->
    <button class="login-btn" @click="handleLogin">登录</button>

    <!-- 注册链接 -->
    <div class="register-link">
      还没有账号？<RouterLink to="/register">立即注册</RouterLink>
    </div>
  </div>
</template>

<script setup>
  import { ref } from 'vue';
  import axios from "axios"
  import config from "@/config"
  import { useRouter } from 'vue-router'


  const router = useRouter();

  // 表单数据
  const form = ref({
    username: '',
    password: ''
  });

  // 登录逻辑（示例）
  const handleLogin = async () => {
    if (!form.value.username || !form.value.password) {
      alert('请填写所有字段');
      return;
    }
    // 这里可以调用 API 提交登录请求
    let response = await axios.post(config.api + 'auth/login', {
      username: form.value.username,
      password: form.value.password
    }, {
      withCredentials: true
    });
    if (response.data.status == '-1') {
      alert(response.data.msg);
    }
    else {
      router.push('/');
    }
  };

</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
  background-color: transparent;
  padding: 40px 20px;
  font-family: 'Arial', sans-serif;
  position: relative;
}

.login-container::before{
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url("@/pic/fengmian4.png");
    background-size: cover;
    background-position: center;
    z-index: -1; /* 确保在内容之下 */
}

/* 标题样式 */
.title {
    width: 100%;
    height: 100px;
    background-image: url("@/pic/login_title.png");
    margin-bottom: 30px;
    background-size: cover;
    background-position: center;
}

/* 表单区域 */
.form {
  width: 100%;
  max-width: 350px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 输入框组 */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 15px;
  color: #555;
}

.input-group input {
  padding: 12px 15px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.3s;
}

.input-group input:focus {
  border-color: #007bff;
}

/* 登录按钮 */
.login-btn {
  margin-top: 25px;
  padding: 14px;
  background-color: #007bff;
  color: white;
  font-size: 16px;
  font-weight: bold;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
  max-width: 350px;
  transition: background-color 0.3s;
}

.login-btn:hover {
  background-color: #0056b3;
}

/* 注册链接 */
.register-link {
  margin-top: 15px;
  font-size: 14px;
  color: #555;
}

.register-link a {
  color: #007bff;
  text-decoration: none;
}

.register-link a:hover {
  text-decoration: underline;
}

/* 小屏适配 */
@media (max-width: 480px) {
  .title {
    font-size: 26px;
  }

  .form, .login-btn {
    max-width: 100%;
  }
}
</style>